//
//  RSAboutSGQRCodeVC.m
//  RSTools
//
//  Created by thinkjoy on 2017/10/16.
//  Copyright © 2017年 杜瑞胜. All rights reserved.
//

#import "RSAboutSGQRCodeVC.h"
#import <AVFoundation/AVFoundation.h>
#import "QRCodeGenerateVC.h"
#import "SGQRCodeScanningVC.h"
#import "RSAuthManage.h"

@interface RSAboutSGQRCodeVC ()

@end

@implementation RSAboutSGQRCodeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor whiteColor];
}

/** 生成二维码方法 */
- (IBAction)generateQRCode:(id)sender {
    QRCodeGenerateVC *VC = [[QRCodeGenerateVC alloc] init];
    [self.navigationController pushViewController:VC animated:YES];
}

/** 扫描二维码方法 */
- (IBAction)scanningQRCode:(id)sender {
    [RSAuthManage judgeDeviceAuthByAuthType:RSAuthManageType_Camera block:^(BOOL isAuth) {
        if (isAuth) {
//            dispatch_sync(dispatch_get_main_queue(), ^{
                SGQRCodeScanningVC *vc = [[SGQRCodeScanningVC alloc] init];
                [self.navigationController pushViewController:vc animated:YES];
//            });
        }
    }];
//    // 1、 获取摄像设备
//    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
//    if (device) {
//        AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
//        if (status == AVAuthorizationStatusNotDetermined) {
//            [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
//                if (granted) {
//                    dispatch_sync(dispatch_get_main_queue(), ^{
//                        SGQRCodeScanningVC *vc = [[SGQRCodeScanningVC alloc] init];
//                        [self.navigationController pushViewController:vc animated:YES];
//                    });
//                    // 用户第一次同意了访问相机权限
//                    NSLog(@"用户第一次同意了访问相机权限 - - %@", [NSThread currentThread]);
//
//                } else {
//                    // 用户第一次拒绝了访问相机权限
//                    NSLog(@"用户第一次拒绝了访问相机权限 - - %@", [NSThread currentThread]);
//                }
//            }];
//        } else if (status == AVAuthorizationStatusAuthorized) { // 用户允许当前应用访问相机
//            SGQRCodeScanningVC *vc = [[SGQRCodeScanningVC alloc] init];
//            [self.navigationController pushViewController:vc animated:YES];
//        } else if (status == AVAuthorizationStatusDenied) { // 用户拒绝当前应用访问相机
//            UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请去-> [设置 - 隐私 - 相机 - SGQRCodeExample] 打开访问开关" preferredStyle:(UIAlertControllerStyleAlert)];
//            UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
//
//            }];
//
//            [alertC addAction:alertA];
//            [self presentViewController:alertC animated:YES completion:nil];
//
//        } else if (status == AVAuthorizationStatusRestricted) {
//            NSLog(@"因为系统原因, 无法访问相册");
//        }
//    } else {
//        UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"未检测到您的摄像头" preferredStyle:(UIAlertControllerStyleAlert)];
//        UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
//
//        }];
//
//        [alertC addAction:alertA];
//        [self presentViewController:alertC animated:YES completion:nil];
//    }
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
